﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using TuongLaiDangCho.DTO;
using System.Data.OleDb;

namespace TuongLaiDangCho.DAO
{
    class ChiTieuDAO
    {
        public static DataTable LoadExpenditure(ChiTieuDTO Expend)
        {
            string sql = "Select * From CHITIEU where NgayThang=#" + Expend.NgayThang.ToShortDateString() + "#";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public static void InsertExpenditure(ChiTieuDTO Expend)
        {
            string sql = "Insert Into CHITIEU(NgayThang,NoiDung,SoTien) values(#"+Expend.NgayThang.ToShortDateString()+"#,'" + Expend.NoiDung + "'," + Expend.SoTien.ToString() + ")";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void UpdateExpenditure(ChiTieuDTO Expend)
        {
            string sql = "Update CHITIEU set NoiDung='" + Expend.NoiDung + "' , Sotien=" + Expend.SoTien.ToString() + " where ID=" + Expend.Id.ToString() + "";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void DeleteExpenditure(ChiTieuDTO Expend)
        {
            string sql="Delete From CHITIEU where ID="+Expend.Id.ToString()+"";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }
    }
}
